{% if contests %}
<script>
$(function () {
	var id = null;
	// verify contest
	$('.icon-user').closest('li').click(function() {
		id = $(this).closest('tr').attr('id');
		$('.modal.verify-contest').modal({ keyboard: false }, 'show');
	});
	$('.btn.verify-submit').click(function() {
		var result = ($(this).hasClass('btn-success')) ? 'success-verify' : 'fail-verify';
		$.post("{{ path('AcmeContestBundle_ContestVerify') }}", { id: id, result: result },
		function (data) {
			if (data == 'success') {
				$('.btn.verify-submit').button('reset');
				$('.modal.verify-contest').modal('hide');
				$('.btn.list-submit').trigger('click');
			}
		});
		id = null;
	});

	// edit contest
	$('.icon-pencil').closest('li').click(function() {
		id = $(this).closest('tr').attr('id');
		$.post("{{ path('AcmeContestBundle_ContestEdit') }}", { id: id, show_modal_request: true },
		function (html) {
			$('.modal.edit-contest div.modal-body').html(html);
			$('.modal.edit-contest').modal({ keyboard: false }, 'show');
		}, "html");
	});
	$('.btn.edit-submit').click(function() {
		$.post("{{ path('AcmeContestBundle_ContestEdit') }}", $('#user_edit form').serialize(),
		function (data) {
			if (data == 'success') {
				$('.btn.edit-submit').button('reset');
			}
		});
		id = null;
	});
	
	// delete contest
	$('.icon-trash').closest('li').click(function() {
		id = $(this).closest('tr').attr('id');
		$.post("{{ path('AcmeContestBundle_ContestDelete') }}", { id: id },
		function (data) {
			if (data == 'success') {
				$('.btn.list-submit').trigger('click');
			}
		});
		id = null;
	});

	// undelete user
	$('.icon-refresh').closest('li').click(function() {
		id = $(this).closest('tr').attr('id');
		$.post("{{ path('AcmeContestBundle_ContestUndelete') }}", { id: id },
		function (data) {
			if (data == 'success') {
				$('.btn.list-submit').trigger('click');
			}
		});
		id = null;
	});
});
</script>

<table class="table table-striped" >
<caption><span style="color: red;">**</span>: 竞赛由系统管理院创建, -: 未定义, ?: 未填写</caption>
	<thead>
		<tr>
			<th>竞赛ID</th>
			<th>竞赛名称</th>
			<th>竞赛类型</th>
			<th>申请人</th>
			<th>申请状态</th>
			<th>评估类型</th>
			<th>标记</th>
			<th>所在大学</th>
			<th>操作</th>
		</tr>
	</thead>
	<tbody>
		{% for contest in contests %}
		<tr id="{{ contest.id }}">
			<td>{{ contest.id }}</td>
			<td>
				{{ contest.name }}
				{% if (contest.createdBy == 0) %}<span style="color: red;">**</span>{% endif %}
			</td>
			<td>
				{{ contest.contestTypeInfo.name }}
				({{ contest.contestTypeInfo.parent.name }})
			</td>
			<td>{{ contest.applyByInfo.userInfo.name }}</td>
			<td>{{ contestApplyState[contest.applyState] }}</td>
			<td>{% if (contest.reviewType) %}{{ contestReviewType[contest.reviewType] }}{% else %}?{% endif %}</td>
			<td>{{ flag[contest.flag] }}</td>
			<td>
				{{ contest.applyByInfo.userInfo.universityInfo.name }}
				({{ contest.applyByInfo.userInfo.universityInfo.areaInfo.fullName }})
			</td>
			<td>
			<div class="btn-group">
				<a href="#" class="btn btn-mini btn-primary"><i class="icon-file icon-white"></i> 竞赛管理</a>
				<a href="#" data-toggle="dropdown" class="btn btn-mini btn-primary dropdown-toggle"><span class="caret"></span></a>
				<ul class="dropdown-menu">
					{% if (flagEn[contest.flag] == 'not-delete') %}
						<li><a href="#"><i class="icon-pencil"></i> 编辑</a></li>
						<li><a href="#"><i class="icon-trash"></i> 删除</a></li>
						
						{% if (contestApplyStateEn[contest.applyState] == 'to-verify') %}
						<li class="divider"></li>
						<li><a href="#"><i class="icon-user"></i> 审核</a></li>
						{% endif %}
						
					{% else %}
						<li><a href="#"><i class="icon-refresh"></i> 还原</a></li>
					{% endif %}
				</ul>
	        </div>
			</td>
		</tr>
		{% endfor %}
	</tbody>
</table>

<div class="modal hide verify-contest">
	<div class="modal-header">
		<a class="close" data-dismiss="modal">×</a>
		<h3>竞赛审核</h3>
	</div>
    <div class="modal-body">
    请选择竞赛审核结果
    </div>
    <div class="modal-footer">
	    <a href="#" class="btn" data-dismiss="modal">关闭</a>
	    <input class="btn btn-danger verify-submit" autocomplete="off" type="button" data-loading-text="提交中..." onclick="$(this).button('loading');" value="失败" />
		<input class="btn btn-success verify-submit" autocomplete="off" type="button" data-loading-text="提交中..." onclick="$(this).button('loading');" value="成功" />
    </div>
</div>

<div class="modal hide edit-contest">
	<div class="modal-header">
		<a class="close" data-dismiss="modal">×</a>
		<h3>编辑竞赛信息</h3>
	</div>
    <div class="modal-body">
    </div>
    <div class="modal-footer">
	    <a href="#" class="btn" data-dismiss="modal">关闭</a>
	    <input class="btn btn-primary edit-submit" autocomplete="off" type="button" data-loading-text="保存中..." onclick="$(this).button('loading');" value="保存" />
    </div>
</div>
{% else %}
No contest have been found.
{% endif %}